/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.welchapps.nporganizer;


import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.view.View;



public class FilterList extends Activity {

    /**
     * Standard projection for the interesting columns of a normal note.
     */

    private EditText mValue;
    private Spinner cat, status;
    ArrayAdapter<CharSequence> adapter_cat, adapter_stat;

    /**
     * A custom EditText that draws lines between each line of text that is displayed.
     */


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Set the layout for this activity.  You can find it in res/layout/note_editor.xml
        setContentView(R.layout.filter_list);
        //final Intent intent = getIntent();

        cat = (Spinner) this.findViewById(R.id.cat_spin);     
        status = (Spinner) this.findViewById(R.id.status_spin);  
        // The text view for our note, identified by its ID in the XML file.
        mValue = (EditText) findViewById(R.id.value);
        // Create an ArrayAdapter using the string array and a default spinner layout
        adapter_cat = ArrayAdapter.createFromResource(this,
                R.array.filter_catlist, android.R.layout.simple_spinner_item);
        // Specify the layout to use when the list of choices appears
        adapter_cat.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        // Create an ArrayAdapter using the string array and a default spinner layout
        adapter_stat = ArrayAdapter.createFromResource(this,
                R.array.filter_status_array, android.R.layout.simple_spinner_item);
        // Specify the layout to use when the list of choices appears
        adapter_stat.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        // Apply the adapter to the spinner
        cat.setAdapter(adapter_cat);
        status.setAdapter(adapter_stat);
        
        SharedPreferences settings = getSharedPreferences("filterPref",0);
        mValue.setText(settings.getString("value",""));
        cat.setSelection(adapter_cat.getPosition(settings.getString("category","None")));
        status.setSelection(adapter_stat.getPosition(settings.getString("status","Both")));
        

    }

    @Override
    protected void onResume() {
        super.onResume();
        // If we didn't have any trouble retrieving the data, it is now
        // time to get at the stuff.

    }



    @Override
    protected void onPause() {
        super.onPause();

    }

    public void okFilter(View view){
    	SharedPreferences settings = getSharedPreferences("filterPref",0);
    	SharedPreferences.Editor editor = settings.edit();
    	
    	editor.putString("category",cat.getSelectedItem().toString());
    	editor.putString("status",status.getSelectedItem().toString());
    	editor.putString("value",mValue.getText().toString());
    	editor.commit();
    	finish();
    }
    
    public void clearFilter(View view){
        mValue.setText("");
        cat.setSelection(adapter_cat.getPosition("None"));    	
        status.setSelection(adapter_stat.getPosition("Both"));   
    }
 

}
